package org.water.sys.repository;

import java.util.List;

import javax.persistence.QueryHint;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.water.base.repository.BaseRepository;
import org.water.sys.entity.SysUser;

/**
 * 用户dao
 * @author qzy
 * 
 */
public interface UserDao extends BaseRepository<SysUser, String> {
	
	/**
	 * 使用命名方式进行查询
	 * @param userName
	 * @return
	 */
	public Page<SysUser> findByUserNameLike(String userName,Pageable pageRequest);
	public Page<SysUser> findByUserNameLikeAndDelStatus(String userName,int delStatus,Pageable pageRequest);
	
	@Query("select u from SysUser u where (u.userName like :userName or u.aliasName like :userName) and u.delStatus=:delStatus")
	public Page<SysUser> findByUserNameLikeOrAliasNameLikeAndDelStatus(@Param("userName") String userName,@Param("delStatus") int delStatus,Pageable pageRequest);
	/**
	 * 使用jpql的参数查询,?1表示第一个参数
	 * @param userName
	 * @return
	 */
	@Query("select u from SysUser u where u.userName like %?1%")
	public List<SysUser> findByUserNameLike2(String userName);
	/**
	 * 使用jpql的命名参数查询
	 * @param userName
	 * @return
	 */
	@Query("select u from SysUser u where u.userName like %:userName%")
	public List<SysUser> findByUserNameLike3(@Param("userName") String userName);
	/**
	 * 修改用户别名  
	 * 注：修改、增加、删除时需要加@Modifying注解
	 * @param id
	 * @param aliasName
	 * @return
	 */
	@Modifying
	@Query("update SysUser u set u.aliasName=:aliasName where u.id=:id")
	public int updateUserAliasName(@Param("id") String id,@Param("aliasName") String aliasName);
	/**
	 * 根据用户名与密码获取用户
	 * @param userName
	 * @param password
	 * @return
	 */
	public SysUser findByUserNameAndPassword(String userName,String password);
	/**
	 * 根据用户名获取用户
	 * @param userName
	 * @return
	 */
	public SysUser findByUserName(String userName);
	
}
